<?php
	class paymentmodel extends Model {
		function paymentmodel()
		{
			parent::Model();			
		}
		
		function add($data)
		{
			$dataDB = array();
            $dataDB['first_name'] = $data['first_name'];		
			$dataDB['last_name'] = $data['last_name'];	
			$dataDB['status'] = $data['status'];	
			$dataDB['mobile_no'] = $data['mobile_no'];	
			$dataDB['email'] = $data['email'];	
			$dataDB['tranfer_method'] = $data['tranfer_method'];	
			$dataDB['transfer_method_0ther'] = $data['transfer_method_0ther'];	
			$dataDB['tranfer_to_account_id'] = $data['tranfer_to_account_id'];			
			$dataDB['amount'] = $data['amount'];	
			$dataDB['pay'] = $data['pay'];	
			$dataDB['pay_detail'] = $data['pay_detail'];	
			$dataDB['transfer_hr'] = $data['transfer_hr'];	
			$dataDB['transfer_min'] = $data['transfer_min'];			
			$dataDB['note'] = $data['note'];	
			$dataDB['is_active'] = '1';
			$this->db->set('update_date', 'NOW()', FALSE);
            $this->db->set('transfer_date', "str_to_date('".$data['transfer_date']."', '%d/%m/%Y')", FALSE); 
			$this->db->insert('payment_transaction', $dataDB);
			return $this->db->insert_id();
		}
		
				
		function update($data, $by)
		{			
            $this->db->where('payment_id', $data['payment_id']);
            if($by != null && $by == 'admin') {
            	$this->db->set('admin_appreve', 'NOW()', FALSE);
            }
			$this->db->update('payment_transaction', $data); 
		}
		
		function countAll()
		{
			$sql = " SELECT t.*, a.account_no, date_format(transfer_date, '%d/%m/%Y') as transfer_date_str  FROM payment_transaction t, tutorland_account a where t.tranfer_to_account_id = a.account_id and t.is_active = '1' order by payment_id desc";
			$query = $this->db->query($sql);  
			$count = $query->num_rows(); 
	  		return $count;
		}
		
		function getAll()
		{
			$sql = " SELECT t.*, a.account_no, date_format(transfer_date, '%d/%m/%Y') as transfer_date_str  FROM payment_transaction t, tutorland_account a where t.tranfer_to_account_id = a.account_id and t.is_active = '1' order by payment_id desc";
			$query = $this->db->query($sql);  
			return $query->result();
		}
		
		function getAllLimit($limit = NULL, $offset = NULL)
		{
			$sql = " SELECT t.*, a.account_no, date_format(transfer_date, '%d/%m/%Y') as transfer_date_str  FROM payment_transaction t, tutorland_account a where t.tranfer_to_account_id = a.account_id and t.is_active = '1' order by payment_id desc ";
			if($limit != null) {
				if($offset != null) {
					$sql .= " limit " . $offset . ", " . $limit;
				} else {
					$sql .= " limit " . $limit;
				}
			}
			$query = $this->db->query($sql);  
	  		return $query->result();
		}
		
		function getByID($id)
		{
			$sql = " SELECT t.*, a.account_no, date_format(transfer_date, '%d/%m/%Y') as transfer_date_str  FROM payment_transaction t, tutorland_account a where t.tranfer_to_account_id = a.account_id and t.is_active = '1'
					 and payment_id = " . $id . " order by payment_id";
			$query = $this->db->query($sql);  
			return $query->row_array();
		}
		
	}
?>